using UnityEngine;
using System.Collections;

public class ColliderShowHUD : MonoBehaviour
{
    public ActionConstants.Action accion = ActionConstants.Action.ACTION_PUSH;
    
    private ShowHUD showHUD;
    private PlayerControl player;
    private GameObject parent;

    void Start()
    {
        // Buscamos al Player por Tag.
        GameObject playerGO = GameObject.FindGameObjectWithTag(StringConstants.TAG_PLAYER);
        if (playerGO)
            player = playerGO.GetComponent<PlayerControl>();
        else
        {
            // Si no tenemos el objetivo.
            Debug.Log("There is no entity tagged 'Player' in the scene, shoud be your character");
            return;
        }

        // guardamos objeto padre
        parent = this.transform.parent.gameObject;

        // componente ShowHUD (script) del hijo
        showHUD = transform.GetComponentInChildren<ShowHUD>();          
        showHUD.texture = transform.GetComponentInChildren<GUITexture>();

        // cargamos la textura correspondiente a la accion
        switch (accion)
        {
            case ActionConstants.Action.NONE:
                showHUD.texture.texture = null;
                break;
            case ActionConstants.Action.ACTION_PUSH:
                showHUD.texture.texture = Resources.Load(StringConstants.TEXTURE_ACTION_MOVE) as Texture;
                break;
                
            default :
                showHUD.texture.texture = Resources.Load(StringConstants.TEXTURE_ACTION_MOVE) as Texture;
                break;
        }
    }


    void OnTriggerEnter(Collider hit)
    {
        if (hit.gameObject.tag == StringConstants.TAG_PLAYER)
        {
            player.setObjectWithAction(parent, accion);
            Debug.Log("Mostramos hud accion");
            showHUD.showHUD = true;
        }
    }

    void OnTriggerExit(Collider hit)
    {
        if (hit.gameObject.tag == StringConstants.TAG_PLAYER)
        {
            player.clearObjectWitAction();
            Debug.Log("Ocultamos hud accion");
            showHUD.showHUD = false;
        }
    }

}
